package com.xtxk.utils.result;

import java.io.Serializable;

import com.xtxk.common.constant.CommonConstant;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;


/**
 * @author tiger
 */
@ApiModel(value="接口返回对象", description="接口返回对象")
@Data
public class Result<T> implements Serializable {
	
	/**
	 * 返回代码
	 */
	@ApiModelProperty(value = "返回代码")
	private Integer responseCode = 0;
	
	/**
	 * 返回数据对象 data
	 */
	@ApiModelProperty(value = "返回数据对象")
	private T data;

	private String responseMsg;

	private static final long serialVersionUID = 1L;

	
	public Result<T> success(String message) {
		this.responseCode = CommonConstant.SC_OK;
		return this;
	}
	
	
	public static Result<Object> ok() {
		Result<Object> r = new Result<Object>();
		r.setResponseCode(CommonConstant.SC_OK);
		return r;
	}
	
	public static Result<Object> ok(String msg) {
		Result<Object> r = new Result<Object>();
		r.setResponseCode(CommonConstant.SC_OK);
		r.setResponseMsg(msg);
		return r;
	}
	
	public static Result<Object> ok(Object data) {
		Result<Object> r = new Result<Object>();
		r.setResponseCode(CommonConstant.SC_OK);
		r.setData(data);
		return r;
	}
	
	public static Result<Object> error(String msg) {
		return error(CommonConstant.SC_INTERNAL_SERVER_ERROR_500, msg);
	}
	
	public static Result<Object> error(int responseCode, String msg) {
		Result<Object> r = new Result<Object>();
		r.setResponseCode(responseCode);
		r.setResponseMsg(msg);
		return r;
	}

	public Result<T> error500(String message) {
		this.responseCode = CommonConstant.SC_INTERNAL_SERVER_ERROR_500;
		return this;
	}
	/**
	 * 无权限访问返回结果
	 */
	public static Result<Object> noauth(String msg) {
		return error(CommonConstant.SC_JEECG_NO_AUTHZ, msg);
	}
}